project(genetic_lego)


#-----------------------------------------------------------------------------
# CMake administrivia
cmake_minimum_required( VERSION 2.8 )
if ( COMMAND cmake_policy )
  cmake_policy( SET CMP0003 NEW )
endif( COMMAND cmake_policy )

#option( BUILD_SHARED_LIBS "Set to ON to build shared libraries" OFF )
#set( LIBRARY_OUTPUT_PATH    bin CACHE PATH "Path to libraries"   FORCE )

set( EXECUTABLE_OUTPUT_PATH bin CACHE PATH "Path to executables" FORCE )
set( UPDATE_TYPE "svn" )
set( CMAKE_COLOR_MAKEFILE ON CACHE BOOL "Color" FORCE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_FILESYSTEM_VERSION=3" )

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug CACHE STRING
        "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
        FORCE)
endif(NOT CMAKE_BUILD_TYPE)


#-----------------------------------------------------------------------------


include(cmake/FindWt.cmake)

SET( Boost_ADDITIONAL_VERSIONS "1.41" "1.42" "1.43" "1.44.0" "1.44" "1.45" "1.46" "1.48" "1.49" )

#boost timer and chrono libs are only needed for development purposes
FIND_PACKAGE( Boost 1.41.0 COMPONENTS thread date_time system signals filesystem serialization timer chrono program_options regex )

#find_package( OpenCV REQUIRED )
include(cmake/FindOpenCV.cmake)

set(EXECNAME genetic_lego.wt)


set( sources
    main.cc
    src/FileDragUploadResource.cpp
    src/GeneticLegoApp.cpp
    src/LegoRenderer.cpp
    js/FileDragUploadResource.js
    src/GeneticEvaluation.cc
    src/dssim.cpp
    src/GeneticLego.cpp
    src/LegoDescription.cpp
)


set( headers
    genetic_lego/FileDragUploadResource.h
    genetic_lego/GeneticEvaluation.h
    genetic_lego/GeneticLegoApp.h
    genetic_lego/LegoRenderer.h
    genetic_lego/dssim.h
    genetic_lego/GeneticLego.h
    genetic_lego/LegoDescription.h
)


add_executable( ${EXECNAME} main.cc ${sources} ${headers} )



include_directories(
    ${Wt_INCLUDE_DIR}
    ${Boost_INCLUDE_DIR}
    ${CMAKE_BINARY_DIR}
    ${OpenCV_INCLUDE_DIR}
    external_libs
    external_libs/include
    .
    /opt/local/include/ImageMagick
   /opt/local/include/opencv
)



target_link_libraries (
    ${EXECNAME}
#    ${Wt_LIBRARIES}
    ${Wt_LIBRARY}
    ${Wt_HTTP_LIBRARY}
#    ${Wt_FCGI_LIBRARY}
    ${Wt_DBO_LIBRARY}
    ${Wt_DBOSQLITE3_LIBRARY}
    ${Boost_LIBRARIES}
#    ${Boost_SYSTEM_LIBRARY}
#    ${Boost_REGEX_LIBRARY}
#    ${Boost_THREAD_LIBRARY}
#    ${Boost_FILESYSTEM_LIBRARY}
#    ${Boost_DATE_TIME_LIBRARY}
#    ${Boost_SIGNALS_LIBRARY}
#    ${Boost_SERIALIZATION_LIBRARY}
#    ${Boost_PROGRAM_OPTIONS}
     ${Boost_TIMER_LIBRARY} 
     ${Boost_CHRONO_LIBRARY}
    ${OpenCV_LIBS}
    ${PROJECT_SOURCE_DIR}/external_libs/lib/libgaul.dylib
    ${PROJECT_SOURCE_DIR}/external_libs/lib/libgaul_util.dylib
    ${PROJECT_SOURCE_DIR}/external_libs/lib/libnn_util.dylib
)



#configure_file(
#    ${CMAKE_CURRENT_SOURCE_DIR}/dubs/DubsConfig.hh.in
#    ${CMAKE_BINARY_DIR}/DubsConfig.hh
#)

FIND_PATH( WT_RESOURCES_DIRECTORY form.css
        ${Wt_INCLUDE_DIR}/../share/Wt/resources
)


IF(NOT WT_RESOURCES_DIRECTORY)
  MESSAGE("Could not find the Wt resources path to copy into current directory")
ELSE(NOT WT_RESOURCES_DIRECTORY)
  MESSAGE("Using Wt resources from ${WT_RESOURCES_DIRECTORY}")
  file(COPY ${WT_RESOURCES_DIRECTORY}
      DESTINATION ${PROJECT_BINARY_DIR}/
      )
ENDIF(NOT WT_RESOURCES_DIRECTORY)



SET(SUPPORT_DIRECTORIES
    genetic_lego_resources
)


foreach(_dir ${SUPPORT_DIRECTORIES})
  file(COPY
    ${PROJECT_SOURCE_DIR}/${_dir}
    DESTINATION
    ${PROJECT_BINARY_DIR}/
    )
endforeach()


#Copy files to the install directory
set(OTHER_FILES
#  wt_config.xml
  runlocal8080.sh
  )

foreach(_file ${OTHER_FILES})
  configure_file(
    ${PROJECT_SOURCE_DIR}/${_file}
    ${PROJECT_BINARY_DIR}/${_file}
    COPYONLY
    )
endforeach()



